﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObserverAndMediator
{
    /// <summary>
    /// 產品類
    /// </summary>
    public class Product : ICloneable
    {
        //產品名稱
        private string name;
        //是否可以屬性變更
        private bool canChanged = false;
        /// <summary>
        /// 產生一個新的產品
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="_name"></param>
        public Product(ProductManager manager, string _name)
        {
            //允許建立產品
            if (manager.isCreateProduct())
            {
                canChanged = true;
                name = _name;
            }
        }

        public string Name
        {
            get { return name; }
            set
            {
                if (canChanged)
                {
                    this.name = value;
                }
            }
        }

        public object Clone()
        {
            Product p = null;
            try {
                p = (Product)this.MemberwiseClone();
            }
            catch (Exception ex) {
                ex.GetBaseException();
            }
            return p;
        }
    }
}
